package com.jfinal.bbsapp.pub;

import org.apache.log4j.Logger;
import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.jfinal.bbsapp.common.kit.FileUtils;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.Ret;

//公用字典控制器
@Path("/pub")
public class PubController extends Controller {	
	private static final String qiniuhostname = PropKit.get("BUCKET_HOST_NAME"); // 默认上传空间
	private final Logger logger = Logger.getLogger(PubController.class);

	@Inject
	private PubService srv;
	
	//获取字典列表
	@Clear
	public void dictlist() {
		renderJson(srv.dictlist(getPara("keys")));
	}
	
	//获取一个字典
	@Clear
	public void getonedict() {
		renderJson(srv.getonedict(getPara("keys")));
	}
	
	//获取七牛token
	@Clear
	public void getbuckettoken() {
		try {
			String token = FileUtils.getBucketToken();
			renderJson(Ret.ok("提交成功").set("token", token).set("qiniuhostname", qiniuhostname).set("code", 20000));
		} catch (Exception e) {
			logger.error("Exception:", e);
			renderJson(Ret.fail("系统异常").set("code", 50000));
		}
	}
	
	//获取关于我们
	@Clear
	public void appinfo() {
		renderJson(srv.appinfo());
	}
	
	//获取注册协议
	@Clear
	public void getagree() {
		renderJson(srv.getagree());
	}
	
}
